package com.android.phoenix.activity.location;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.phoenix.R;

/**
 * @ClassName: OfflineMapActivity2
 * @Description: 离线地图类
 * @author: OfflineMapActivity2
 * @date: 2015-2-7 下午10:32:17
 */
public class OfflineMapActivity2 extends FragmentActivity implements
		OnClickListener {
	private final static int ALL = 0;
	private final static int DOWNLOAD = 1;

	private ImageView imgOfflineMapBack = null;
	private TextView tvOfflineMapAll = null;
	private TextView tvOfflineMapDownload = null;

	private int currentShow = ALL;
	private View[] fraOfflineMaps = new View[2];

	private Animation aniLeftOut, aniLeftIn, aniRightIn, aniRightOut;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.acti_offline_map2);

		initViews();
	}

	/**
	 * @Title: initViews
	 * @Description: 控件等初始化
	 * @author: WanChao
	 * @date: 2015-2-7 下午10:31:49
	 */
	private void initViews() {
		imgOfflineMapBack = (ImageView) findViewById(R.id.imgOfflineMapBack);
		tvOfflineMapAll = (TextView) findViewById(R.id.tvOfflineMapAll);
		tvOfflineMapDownload = (TextView) findViewById(R.id.tvOfflineMapDownload);
		imgOfflineMapBack.setOnClickListener(this);
		tvOfflineMapAll.setOnClickListener(this);
		tvOfflineMapDownload.setOnClickListener(this);

		fraOfflineMaps[ALL] = findViewById(R.id.fraOfflineMapAll);
		fraOfflineMaps[DOWNLOAD] = findViewById(R.id.FraOfflineMapDownload);
		fraOfflineMaps[DOWNLOAD].setVisibility(View.GONE);

		aniLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
		aniLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
		aniRightOut = AnimationUtils
				.loadAnimation(this, R.anim.slide_right_out);
		aniRightIn = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.imgOfflineMapBack:
			finish();
			break;
		case R.id.tvOfflineMapAll:
			changeTitleStatus(ALL);
			break;
		case R.id.tvOfflineMapDownload:
			changeTitleStatus(DOWNLOAD);
			break;
		}
	}

	/**
	 * @Title: changeTitleStatus
	 * @Description: 切换"全部"和"已下载"
	 * @author: WanChao
	 * @date: 2015-2-7 下午10:32:48
	 * @param show
	 */
	private void changeTitleStatus(int show) {
		if (currentShow == show) {
			return;
		}
		if (show == ALL) {
			tvOfflineMapAll
					.setTextColor(getResources().getColor(R.color.white));
			tvOfflineMapAll
					.setBackgroundResource(R.drawable.shape_offlinemap_left_yes);
			tvOfflineMapDownload.setTextColor(getResources().getColor(
					R.color.offmaptitlebg_yes));
			tvOfflineMapDownload
					.setBackgroundResource(R.drawable.shape_offlinemap_right_no);
			fraOfflineMaps[ALL].startAnimation(aniLeftIn);
			fraOfflineMaps[DOWNLOAD].startAnimation(aniRightOut);
			fraOfflineMaps[ALL].setVisibility(View.VISIBLE);
			fraOfflineMaps[DOWNLOAD].setVisibility(View.GONE);
		} else if (show == DOWNLOAD) {
			tvOfflineMapAll.setTextColor(getResources().getColor(
					R.color.offmaptitlebg_yes));
			tvOfflineMapAll
					.setBackgroundResource(R.drawable.shape_offlinemap_left_no);
			tvOfflineMapDownload.setTextColor(getResources().getColor(
					R.color.white));
			tvOfflineMapDownload
					.setBackgroundResource(R.drawable.shape_offlinemap_right_yes);
			fraOfflineMaps[ALL].startAnimation(aniLeftOut);
			fraOfflineMaps[DOWNLOAD].startAnimation(aniRightIn);
			fraOfflineMaps[ALL].setVisibility(View.GONE);
			fraOfflineMaps[DOWNLOAD].setVisibility(View.VISIBLE);
		}
		currentShow = show;
	}
}
